/**
 * Created by wdj on 16/9/20.
 * LaunchController
 */

import Controller from '../Controller';
import content from '../../pages/index.jade';
var $ = Dom7;

export default class LaunchController extends Controller{

    onCreated(app, page) {
        this.loadIndex();

        // 处理toolbar
        $('.home-toolbar-container').on('click', 'a.link', function () {
            var $a = $(this);
            // $a.siblings().removeClass('active');
            // $a.addClass('active');
            if($a.hasClass('back-to-home')){
                page.view.back({
                    //url: '#index',
                    pageName: 'index',
                    force: true
                });
                return false;
            }

            if($a.data('page-name') === $(document.body).data('page-name')){
                return false;
            }else{
                page.view.loadPage($a.data('href'))
            }
        });
    }

    onShown(app, page) {
        this.loadIndex();
    }

    loadIndex(){
        setTimeout(()=>{
            this.app.mainView.router.load({
                //url: 'pages/index.jade',
                content: content(),
                reload: true,
                animatePages: false
            });
        }, 10)
    }
}

